export default {
    data() {
        return {
            price: '',
            id: '',
            name: '',
            code: '',
            notes: '',
            order_id: '',
            logo:''
        }
    },
    onLoad(e) {
        console.log(e.id)
        let id = e.id || 0;
        this.id = id;
        this.getstore()

        // this.getCode();
    },
    methods: {
        pay2(config) {
            console.log(config, 'ccc2')
            tt.requestOrder({
                data: config.data, // 请勿在前端对data做任何处理
                byteAuthorization: config.byteAuthorization, // 请勿在前端对byteAuthorization做任何处理
                success: (res) => {
                    tt.getOrderPayment({
                        orderId: res.orderId, // 请勿在前端对data做任何处理
                        success: (res) => {
                            console.log("成功", res);
                            this.navigationTo('/pages/success/index')
                            this.price = ''
                        },
                        fail: (res) => {
                            console.log(res);
                        },
                    });
                    console.log("成功", res);
                },
                fail: (res) => {
                    console.log(res);
                },
            });
        },
        getprepay: function () {
            this.$post('pay/prepay',
                { pay_way: 4, order_id: this.order_id, from: 'order_code' }
            ).then(res => {
                if (res.code == 1) {
                    this.pay2(res.data.config)
                } else {
                    this.uniToast(res.msg)
                }
            }).finally(() => {
            })
        },
        submit: function () {

            tt.login({
                force: true,
                success: (res) => {
                    this.code = res.code;
                    console.log(`login 调用成功${res.code}`);

                    this.$post('order.orderCode/submit',
                        {
                            code: res.code,
                            id: this.id,
                            money: this.price,
                            notes: this.notes
                        }
                    ).then(res => {
                        if (res.code == 1) {
                            this.order_id = res.data.order_id || '';
                            this.getprepay();
                        } else {
                            this.uniToast(res.msg)
                        }
                    }).finally(() => {
                    })
                },
                fail: (res) => {
                    console.log(`login 调用失败`);
                },
            });

        },
        getCode: function () {


        },
        getstore: function () {
            this.$get('store.store/store',
                { id: this.id }
            ).then(res => {
                if (res.code == 1) {
                    this.name = res.data.name
                    this.logo = res.data.logo
                } else {
                    this.uniToast(res.msg)
                }
            }).finally(() => {
            })
        },
        clearPrice: function () {
            this.price = ''
        },
        delPrice: function () {
            let price = this.price
            this.price = price.slice(0, -1);
        },
        selPrice: function (val) {
            let price = this.price
            price += ''

            if (val == '.') {
                if (!price) {
                    price += '0.'
                }
                // console.log(price.indexOf('.') != -1)
                if (price.indexOf('.') == -1) {
                    price += val;
                }
            } else {
                if (price.length == 1 & val == 0 && price == 0) {
                    return
                } else {
                    price += val;
                }

            }
            this.price = price


        },

    }
}